package _7_集合._3_Set;

import org.junit.jupiter.api.Test;

import java.util.*;

public class SetTest {

    @Test
    public void HashSetTest(){
        Set<String> set = new HashSet<>();
        set.add("apple");
        set.add("banana");
        set.add("pear");
        set.add("orange");
//        for (String s : set){
//            System.out.println(s);
//        }
//        System.out.println("---------------------");
        Iterator<String> iterator = set.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }

    @Test
    public void HashSetTest1(){
        Set<String> set = new HashSet<>(
                Arrays.asList(
                        "banana",
                        "apple",
                        "pear",
                        "orange"
        ));
//        for (String s:set
//             ) {
//            System.out.println(s);
//        }
        Iterator<String> iterator = set.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }

    @Test
    public void TreeSetTest(){
        Set<String> set = new TreeSet<>();
        set.add("banana");
        set.add("apple");
        set.add("pear");
        set.add("orange");
//        for (String s : set){
//            System.out.println(s);
//        }
        Iterator<String> iterator = set.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }
}
